package stock

import "time"

// IsMarketOpen 股票交易时间
func IsMarketOpen() bool {
	// todo 节假日休市
	// 获取当前时间
	currentTime := time.Now()

	// 设置中国股市交易时间范围
	tradingStartTimeAM := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 9, 30, 0, 0, time.Local)
	tradingEndTimeAM := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 11, 30, 0, 0, time.Local)
	tradingStartTimePM := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 13, 0, 0, 0, time.Local)
	tradingEndTimePM := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 15, 0, 0, 0, time.Local)

	// 判断当前时间是否在交易时间范围内
	return (currentTime.After(tradingStartTimeAM) && currentTime.Before(tradingEndTimeAM)) ||
		(currentTime.After(tradingStartTimePM) && currentTime.Before(tradingEndTimePM))
}
